<?php


namespace app\admin\controller;


use app\service\orderService;
use think\Db;
use think\db\Where;

class CxyunCarType extends Common
{

    public function index(){
        //根据当前账号查询区域
        $com = $this->pidTokenId();
        $whe=new Where();
        $whe['community_id'] = array('in',implode(',',$com['community_id']));
        //根据账号查询停车场
        $parkinglist = (new orderService())->parkingList($whe);
        $this->assign('parkinglist',$parkinglist);
        //查询停车场ID
        if(!empty($parkinglist)){
            foreach($parkinglist as $park){
                $parkingNo[] = $park['parkingNo'];
            }
            //将数组转换成字符串
            $parkingNo = implode(',',$parkingNo);
        }else{
            $parkingNo = null;
        }
        $community_id = $com['community_id'];
        //搜索
        $data = request()->get();
        // dump($data);
        $where=array();
        if (!empty($data)){
            if(!empty($data['parkingNo'])){
                $where[]=['parkingNo','=',$data['parkingNo']];
                //$where['parkingNo'] = $data['parkingNo'];//停车场名称
            }

            $this->assign('where',$where);
            $where = array_filter($where);
        }else{
            $where=array();
        }

        $export = json_encode($where);
        $export = str_replace("\"","|",$export);
        $this->assign('export',$export);
        $page = request()->has('page') ? request()->get('page') : 1;
        //多条件查询地库车位信息
        $list = Db::name('cxyun_car_type')->where('parkingNo', 'in', $parkingNo)->where($where)->order('id desc')->paginate(100, false, [
            'page'  =>  $page,
            'query' =>  $where
        ]);
        $number = Db::name('cxyun_car_type')->where('parkingNo', 'in', $parkingNo)->where($where)->count();
        $this->assign('number',$number);

        $this->assign('datalist',$list);
        $this->assign('list',$list);
        foreach ($data as $k => $v) {
            $this->assign($k, $v);
        }
        return $this->fetch('index');
    }


    public function add(){

    }
}